
const { ProcessMgr } = require("./processMgr");
const { SIGNAL_DEFINE } = require("./signal");

class DealProcessMgr extends ProcessMgr  {
    constructor () {
        super();
        this.deckMgr = null;        
        this.cardNum = 3;   // 每人发几张牌
        this.dealCardTime = 0;
    }

    doAction() {
        console.log("执行了DealProcessMgr的doAction方法");
        this.deckMgr.shuffle();     // 洗牌
        this.dealCard();    // 发牌

        // 下一个阶段
        if (this.dealCardTime > 0) {
            setTimeout(this.doNextAction(), this.dealCardTime * 1000);
        } else {
            this.doNextAction();
        }
    }

    setDeckMgr(deckMgr) {
        this.deckMgr = deckMgr;
    }

    setCardNum(cardNum) {
        this.cardNum = cardNum;
    }

    setDealCardTime(dealCardTime) {
        this.dealCardTime = dealCardTime;
    }

    dealCard() {
        var gambers = this.seatMgr.getGambers();
        for (let i = 0; i < this.cardNum * gambers.length; ++i) {
            if (gambers[i] == null) continue;
            var card = this.deckMgr.draw();
            gambers[i].holds.push(card);
        }
        console.log("发牌了", gambers);
        this.signal.emit(SIGNAL_DEFINE.INIT_GAMBER_INFO, gambers);
    }

}

exports.DealProcessMgr = DealProcessMgr;